// *** LICENSE HEADER ***
// Filename: ./guielement.h
// This file is part of Nodewarz 0.1
// Nodewarz is a 3d OpenGL strategy game
// Copyright (C) 2007 CZestmyr
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// *** END LICENSE HEADER ***
#ifndef NODEWARS_GUIELEMENT_H
#define NODEWARS_GUIELEMENT_H

#include <cstring>
#include <SDL.h>
#include <GL/gl.h>

class fonts;

//Abstract class 
class guielement{
    public:
        guielement(int newPosX, int newPosY, const char* newText, int newId);
        //Virtual destructor is needed
        virtual ~guielement();

        //Sets the pointer to the next gui element in the element list of the gui
        void SetNext(guielement* newNext);
        //Sets the text of this gui element
        virtual void SetText(const char* newText);
        //Returns the pointer to the next gui element
        guielement* GetNext();
        //Returns the text buffer of this element
        char* GetText();
        //Enables the element
        void Enable();
        //Disables the element
        void Disable();
        //Returns the enabled state of this element
        bool IsEnabled();

        //Deactivates this element
        virtual void Deactivate();
        //Activates the element
        virtual void Activate();

        //Returns the element id
        int GetId();

        //Clicks the element
        virtual int Click(int clickX, int clickY) = 0;
        //Releases the element
        virtual int Release(int clickX, int clickY) = 0;

        //Sends a key press event to the element
        virtual void KeyPress(SDLKey key, char c) {};

        //Draws the element
        virtual void Draw(fonts* fontDrawer) = 0;

        //Sets the global gui colors
        static void SetColors(GLubyte red, GLubyte green, GLubyte blue,
                              GLubyte textRed, GLubyte textGreen, GLubyte textBlue);
    protected:
        //Frees the element text buffer
        void FreeBuffer();

        //Element id and flags
        int id;
        bool enabled;
        bool active;

        //Element position
        int x, y;
        //The element text buffer
        char* textBuffer;

        //GLobal gui colors
        static GLubyte r, g, b;
        static SDL_Color textColor;
        static SDL_Color disabledTextColor;

        //Pointer to the next gui element in the element list
        guielement* next;
};

#include "fonts.h"

#endif
